﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// 
    /// </summary>
    public class ResampleFilter : BaseImageFilter
    {
        protected int m_nCount = 1;
        protected IIteratedFilter[] m_aFilter = null;
        protected bool m_bResample = false;

        /// <summary>
        /// default
        /// </summary>
        public ResampleFilter()
        {
        }

        /// <summary>
        /// used to create a deep copy
        /// </summary>
        /// <param name="_resampleFilter"></param>
        internal ResampleFilter(ResampleFilter _resampleFilter)
        {
        }

        public int Count
        {
            get { return m_nCount; }
            set { m_nCount = value; }
        }

        public bool Resample
        {
            get { return m_bResample; }
            set { m_bResample = value; }
        }

        public IIteratedFilter[] Filter
        {
            get { return m_aFilter; }
            set { m_aFilter = value; }
        }

        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            Resampler r = new Resampler();
            UnsafeBitmap bitmapNew = r.Resample(_bitmap, m_nCount, m_bResample, m_aFilter);

            int nWidth = _bitmap.Width;
            int nHeight = _bitmap.Height;

            for (int y = 0; y < nHeight; y++)
            {
                for (int x = 0; x < nWidth; x++)
                {
                    Color color1 = _bitmap.GetPixel(x,y);
                    Color color2 = bitmapNew.GetPixel(x,y);
                    Color color = Color.FromArgb(ColorFunctions.DistanceSquared(color1, color2));
                    _bitmap.SetPixel(x, y, color);
                }
            }
            return base.Execute(_bitmap);
        }

        /// <summary>
        /// Used to create a copy
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new ResampleFilter(this);
        }
    }
}
